package com.tanhua.server.controller;

import com.tanhua.dubbo.enums.CommentType;
import com.tanhua.server.service.IMService;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.UserInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("messages")
@RestController
@Slf4j
public class IMController {

    @Autowired
    private IMService imService;

    /**
     * 根据环信用户名查询用户信息
     *
     * @param userName 环信用户
     * @return
     */
    @GetMapping("userinfo")
    public UserInfoVo queryUserInfoByUserName(@RequestParam("huanxinId") String userName) {
        return this.imService.queryUserInfoByUserName(userName);
    }

    /**
     * 联系人添加
     *
     * @return
     */
    @PostMapping("contacts")
    public Object addContacts(@RequestBody Map<String, Long> param) {
        Long userId = param.get("userId");
        return this.imService.addContacts(userId);
    }


    /**
     * 查询联系人列表
     *
     * @param page
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("contacts")
    public PageResult queryContactsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                        @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                        @RequestParam(value = "keyword", required = false) String keyword) {
        return this.imService.queryContactsList(page, pageSize, keyword);
    }


    //查询点赞列表
    @GetMapping("/likes")
    public PageResult queryLikesList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                     @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return this.imService.queryCommentListByType(page, pageSize,CommentType.LIKE);
    }

    //查询喜欢列表
    @GetMapping("/loves")
    public PageResult queryLovesList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                     @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return this.imService.queryCommentListByType(page, pageSize,CommentType.LOVE);
    }

    //查询评论列表
    @GetMapping("/comments")
    public PageResult queryCommentsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                        @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return this.imService.queryCommentListByType(page, pageSize,CommentType.COMMENT);
    }

    //查询公告列表
    @GetMapping("/announcements")
    public PageResult queryAnnouncementsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                             @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return this.imService.queryAnnouncementsList(page, pageSize);
    }

}
